//
//  ECSelectCommodityViewController.m
//  ECERP.CRM
//
//  Created by 刘思麟 on 2018/10/26.
//  Copyright © 2018年 Mac. All rights reserved.
//

#import "ECSelectCommodityViewController.h"
#import "ECCommodityMenuView.h"
#import "ECSelectTagView.h"

@interface ECSelectCommodityViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) ECSelectTagView * topTagView;

@property (nonatomic,strong) ECCommodityMenuView * menuView;

@end

@implementation ECSelectCommodityViewController

- (void)viewDidLoad {
    self.navigationItem.title = @"选择商品";
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"search_icon"] style:UIBarButtonItemStylePlain target:self action:nil];
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)loadSubView {
    __weak typeof(self) weakSelf = self;
    self.topTagView = [ECSelectTagView new];
    [self.view addSubview:self.topTagView];
    self.topTagView.frame = CGRectMake(0, 0, ECSCREEN_WIDTH, 10);
    self.topTagView.tagStrs = @[@"哇哈哈",@"哇哈哈",@"哇哈哈",@"哇哈哈"].mutableCopy;
    self.menuView = [ECCommodityMenuView new];
    self.menuView.menuTableViewDataSource = self;
    self.menuView.commodityListTableViewDelegate = self;
    [self.menuView.menuTableView registerClass:[ECCommodityMenuTableViewCell class] forCellReuseIdentifier:@"cell"];
    [self.view addSubview:self.menuView];
    [self.menuView.menuTableView reloadData];
    [self.menuView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(weakSelf.view);
        make.top.mas_equalTo(weakSelf.topTagView.mas_bottom);
    }];
    
    if (self.menuView.menuTableView.delegate) {
        [self.menuView.menuTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:YES scrollPosition:UITableViewScrollPositionTop];
        [self.menuView.menuTableView.delegate tableView:self.menuView.menuTableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
    }
    
    [self requestForCustomerLevel:self.customerLevelId];
}

- (void)requestForCustomerLevel:(NSString *)customerLevelID {
    if (!customerLevelID) {
        return;
    }
    [GLHTTPTool getWithURL:Api_CustomerLevelPriceMaterialType params:@{@"customerLevelId":customerLevelID} success:^(id json) {
        
    } failure:^(NSError *error) {
        
    }];
}

#pragma mark UITableViewDelegate,UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 11;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView == self.menuView.menuTableView) {
        return 40 * PX_RELATIVE375;
    }
    return 90 * PX_RELATIVE375;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView == self.menuView.menuTableView) {
        ECCommodityMenuTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
        cell.titlLB.text = @"哇哈哈";
        return cell;
    }
    return [UITableViewCell new];
}

@end
